'''
Created on 2011-1-24

@author: Madlee
'''
from os.path import normpath, isfile, isdir
from os import makedirs, rmdir, remove, listdir, getcwd 
from shutil import copyfile

class BasicConnection:
    def open(self):
        raise NotImplementedError()
    
    def close(self):
        raise NotImplementedError()
    
    def execute(self, command):
        raise NotImplementedError()

    def upload(self, localfile, remotefile):
        raise NotImplementedError()
    
    def download(self, remotefile, localfile):
        raise NotImplementedError()

    def mkdir(self, dirname):
        raise NotImplementedError()
    
    def rmdir(self, dirname):
        raise NotImplementedError()
    
    def rmfile(self, filename):
        raise NotImplementedError()
    
    def is_file(self, filename):
        raise NotImplementedError()
    
    def is_dir(self, dirname):
        raise NotImplementedError()
        
    def list_dir(self, dirname):
        raise NotImplementedError()
    
    def get_cwd(self):
        raise NotImplementedError()
    
    
class LocalHostConnection(BasicConnection):
    def open(self):
        pass
    
    def close(self):
        pass
    
    def execute(self, command):
        # TODO:
        raise NotImplementedError()

    def upload(self, localfile, remotefile):
        localfile = normpath(localfile)
        remotefile = normpath(remotefile)
        if localfile != remotefile:
            copyfile(localfile, remotefile)    
        
    
    def download(self, remotefile, localfile):
        remotefile = normpath(remotefile)
        localfile = normpath(localfile)
        if localfile != remotefile:
            copyfile(remotefile, localfile)

    def mkdir(self, dirname):
        makedirs(dirname)
    
    def rmdir(self, dirname):
        rmdir(dirname)
    
    def rmfile(self, filename):
        remove(filename)
    
    def is_file(self, filename):
        return isfile(normpath(filename))
    
    def is_dir(self, dirname):
        return isdir(dirname)
        
    def list_dir(self, dirname):
        return listdir(dirname)
    
    def get_cwd(self):
        return getcwd()    

class JobManager:
    pass


class JobMonitor:
    pass